#
# @lc app=leetcode.cn id=1006 lang=python3
#
# [1006] 笨阶乘
#

# @lc code=start
import math
class Solution:
    def clumsy(self, N: int) -> int:
        # signal = {0:'*', 1:'/', 2:'+', 4:'-'}
        store = [N]
        for i in range(N-1):
            num = N-i-1
            # print(store, num)
            signal = i%4
            if signal==0:
                tmp = store.pop()
                store.append(int(tmp*num))
            elif signal == 1:
                tmp = store.pop()
                if tmp>0:
                    store.append((tmp//num))
                else:
                    store.append(-(abs(tmp)//num))
            elif signal == 2:
                store.append(num)
            elif signal == 3:
                store.append(-num)
            # print(i, num, signal, store)
        return sum(store)

# @lc code=end

if __name__ == '__main__':
    solution = Solution()
    N = 1444
    print(solution.clumsy(N))